<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<%@ taglib uri="/tld/extremecomponents" prefix="ec" %>
<%@ include file="../../common/common.jsp" %>	
<%@ include file="master_pass.jsp" %>
<% 	
masterLogin.hasPermission(3005);
//权限判断代码结束
Integer classId = Utility.parseInt(request.getParameter("classId"));
Integer userId = Utility.parseInt(request.getParameter("userId"));

IClassPermissionService classPermissionService = (IClassPermissionService)BeanManager.getBean("classPermissionService");
List haveList = classPermissionService.listByUserId(classId,userId);
List notHaveList = classPermissionService.listNotByUserId(classId,userId);
request.setAttribute("haveList",haveList);
request.setAttribute("notHaveList",notHaveList);
%>
<html>
<head>
<title><%=SYSTITLE%> - 社区版主权限管理</title>
<%@ include file="../../common/meta.inc" %>
<link href="css.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/extremetable/extremecomponents.css"/>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/common-validator.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/prototype.js"></script>
<script language="javascript" src="${pageContext.request.contextPath}/scripts/buffalo/buffalo.js"></script>
<script language="javascript">
var END_POINT="${pageContext.request.contextPath}/buffalo";
var buffalo = new Buffalo(END_POINT);

function doSubmit() {

	form = document.theform;
	
	if(!validateForm(form))
		return;

	var classId= <%=classId%>;
	var userId= <%=userId%>;
	var permissionCodes = new Array();
	
	var permissionCodeOptionLen = form.haveId.options.length;
	for(i=0;i< permissionCodeOptionLen; i++)
	{
		var permissionCodeOption = form.haveId.options(i);
		permissionCodes[i] = permissionCodeOption.value;
	}	
	buffalo.remoteCall("classPermissionServiceAjaxService.updateUser",[classId,userId,permissionCodes.toString()], function(reply) {
        ajaxSubmit(reply.getResult(),"保存成功！","back");
    });	
}


function validateForm(form)
{
	var permissionCodeOptionLen = form.haveId.options.length;
	if(permissionCodeOptionLen<=0)
	{
		sl_alert("请先选择权限！");
		return false;
	}	
	return true;
}
</script>
</head>
<body>
<script language="javascript">
  setTitle("版面管理","设定版主权限");
</script>
<form name="theform">
	<table class="bluetable" width="100%">							
		<tr>
         <th colspan="2" align="right">设定版主权限</th>
       	</tr>
		<tr>
			<td>
				<table>
					<tr>
						<td class="title" align="center">权限列表</td>
						<td class="title">&nbsp;</td>
						<td class="title" align="center">目标列表</td>
					</tr>
					<tr>
						<td><select name="notHaveId" id="notHaveId" size="20" multiple="multiple" style="width:250px;">
								<c:forEach items="${notHaveList}" var="permission">
									<option value="${permission.permissionCode }">${permission.permissionName }</option>
								</c:forEach>
							</select>
						</td>
						<td>
							<table width="100%">
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveOne(document.theform.notHaveId,document.theform.haveId);">&gt;</button></td>
								</tr>
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveAll(document.theform.notHaveId,document.theform.haveId);">&gt;&gt;</button></td>
								</tr>
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveOne(document.theform.haveId,document.theform.notHaveId);">&lt;</button></td>
								</tr>
								<tr>
									<td align="center"><button class="btn btnEx" onclick="javascript:moveAll(document.theform.haveId,document.theform.notHaveId);">&lt;&lt;</button></td>
								</tr>
							</table>
						</td>						
						<td><select name="haveId" id="haveId" size="20" multiple="multiple" style="width:250px;">
								<c:forEach items="${haveList}" var="permission">
									<option value="${permission.permissionCode }">${permission.permissionName }</option>
								</c:forEach>
							</select></td>
					</tr>
				</table>
			</td>
		</tr>																																									
	</table>
	<table border="0" width="100%">
		<tr valign="top">
			<td align="right">
				<button class="btn" accessKey=s id="btnSave" name="btnSave" onclick="javascript:doSubmit();">保存(<u>S</u>)</button>
				&nbsp;&nbsp;
				<button class="btn" accessKey=c id="btnCancel" name="btnCancel" onclick="javascript:history.back();">取消(<u>C</u>)</button>
				&nbsp;&nbsp;
			<td>
		</tr>
	</table>
</form>	
</body>
</html>
